import config from "./config.js";
export const bugs = [];
// 小虫子
export default class Bug {
  constructor(app, options) {
    this.$app = app;
    this.$options = Object.assign(
      {
        bgColor: "#333",
      },
      options
    );

    this.$el = this.element();
    bugs.push(this);
  }

  element() {
    const div = document.createElement("div");
    div.classList.add("snake");
    div.style.backgroundColor = this.$options.bgColor;
    div.style.left = this.$options.left + "px";
    div.style.top = this.$options.top + "px";
    div.style.width = config.width + "px";
    div.style.height = config.height + "px";
    return div;
  }

  //获取的位置
  static get left() {
    return bugs[0].$el.offsetLeft;
  }

  static get top() {
    return bugs[0].$el.offsetTop;
  }

  static remove() {
    const bug = bugs.pop();
    bug.$el.remove();
  }
}
